/**
 * Created on Tue Apr 12 22:25:15 CST 2011
 * Copyright SinoBest, 2010-2011, All rights reserved.
 */package cn.com.test.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.test.dao.Uploadfile;


/**
 * @Author zhou
 * @Date Tue Apr 12 22:25:15 CST 2011
 * @to-do 
 */public class UploadfileDAO extends HibernateDaoSupport {
	
	private static final Log log = LogFactory.getLog(UploadfileDAO.class);
	
	// property constants
	public static final String SYSTEMID = "systemid";
	public static final String NAME = "name";
	public static final String IP_FROM = "ipFrom";
	public static final String URL = "url";
	public static final String CREATEUERID = "createuerid";
	public static final String CREATETIME = "createtime";
	public static final String CREATEUSERNAME = "createusername";
	
	// property constants
	protected void initDao() {
		// do nothing
	}
	
	public void save(Uploadfile transientInstance) {
		log.debug("saving Uploadfile instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void delete(Uploadfile persistentInstance) {
		log.debug("deleting Uploadfile instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public Uploadfile findById(java.lang.String id) {
		log.debug("getting Uploadfile instance with id: " + id);
		try {
			Uploadfile instance = (Uploadfile) getHibernateTemplate().get(
					"cn.com.test.dao.Uploadfile", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public List findAll() {
		log.debug("finding all Uploadfile instances");
		try {
			String queryString = "from Uploadfile";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public Uploadfile merge(Uploadfile detachedInstance) {
		log.debug("merging Uploadfile instance");
		try {
			Uploadfile result = (Uploadfile) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
	
	public void attachDirty(Uploadfile instance) {
		log.debug("attaching dirty Uploadfile instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Uploadfile instance) {
		log.debug("attaching clean Uploadfile instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static UploadfileDAO getFromApplicationContext(ApplicationContext ctx) {
		return (UploadfileDAO) ctx.getBean("UploadfileDAO");
	}
	
	public List findByExample(Uploadfile instance) {
		log.debug("finding Uploadfile instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
	
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Uploadfile instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Uploadfile as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findBySystemid(Object systemid) {
		return findByProperty(SYSTEMID, systemid);
	}
	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}
	public List findByIpFrom(Object ipFrom) {
		return findByProperty(IP_FROM, ipFrom);
	}
	public List findByUrl(Object url) {
		return findByProperty(URL, url);
	}
	public List findByCreateuerid(Object createuerid) {
		return findByProperty(CREATEUERID, createuerid);
	}
	public List findByCreatetime(Object createtime) {
		return findByProperty(CREATETIME, createtime);
	}
	public List findByCreateusername(Object createusername) {
		return findByProperty(CREATEUSERNAME, createusername);
	}

}